package com.example.sms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sms.entity.Course;
import com.example.sms.mapper.CourseMapper;
import com.example.sms.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Override
    public List<Course> getCourses(Integer teacherId) {
        //分页查询所有课程
        return courseMapper.getCoursesByTeacherId(teacherId);
    }

    @Override
    public Course addCourse(Course course) {
        courseMapper.insert(course);
        courseMapper.addInfoToTeacherCourse(course.getId() , course.getTeacherId());
        return courseMapper.selectById(course.getId());
    }

    @Override
    public Integer delCourse(Integer id) {
        courseMapper.deleteInfoInTeacherCourse(id);
        return courseMapper.deleteById(id);
    }

    @Override
    public void delFromTeacherCourse(Integer id) {
        courseMapper.deleteInfoInTeacherCourse(id);
    }

    @Override
    public Integer addToTeacherCourse(Course course) {
        return courseMapper.addInfoToTeacherCourse(course.getId() , course.getTeacherId());
    }

    @Override
    public Boolean checkTeacherCourse(Integer teacherId, Integer courseId) {
        return courseMapper.checkTeacherCourse(teacherId, courseId);
    }

    @Override
    public Integer addToTeacherCourse(Integer courseId, Integer teacherId) {
        return courseMapper.addToTeacherCourse(courseId, teacherId);
    }

    @Override
    public boolean checkTeacherStudent(Integer teacherId, Integer studentId) {
        return courseMapper.checkTeacherStudent(teacherId, studentId);
    }

    @Override
    public List<Course> getCoursesByTeacherId(Integer teacherId) {
        return courseMapper.getCoursesByTeacherId(teacherId);
    }


}
